package com.apache.passport.tomcat;

import com.apache.api.vo.ParamsVo;
import com.apache.cache.service.impl.redis.JedisSsoUtil;
import com.apache.cache.util.Validator;
import com.apache.passport.entity.BlackRoster;
import com.apache.passport.manager.BlackRosterManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * description:定时任务(清除非正常退出时的登录信息)
 *
 * @author dyh 创建时间：2018年03月13日
 */
@Component
@EnableScheduling
public class ScheduledPool {

    //每两小时执行一次
    @Scheduled(fixedRate = 2*60*60000)
    public void countFormulaTab() {
        if(JedisSsoUtil.getInstance().isRedisCache()){
            List<String> keys = JedisSsoUtil.getInstance().getListForSpaceKey("loginToken", 0, 0);
            if(!Validator.isEmpty(keys)){
                for(String key:keys){
                    if(JedisSsoUtil.getInstance().getCacheObjectByKey(key)==null){
                        JedisSsoUtil.getInstance().delListInfo("loginToken",key);
                    }
                }
            }
            keys = JedisSsoUtil.getInstance().getListForSpaceKey("loginErrToken", 0, 0);
            if(!Validator.isEmpty(keys)){
                for(String key:keys){
                    if(JedisSsoUtil.getInstance().getCacheObjectByKey(key)==null){
                        JedisSsoUtil.getInstance().delListInfo("loginErrToken",key);
                    }
                }
            }
        }
    }
}
